import 'package:flutter/material.dart';

import '../util/ColorUtil.dart';

class ToggleableButton extends StatefulWidget {
  final VoidCallback? onPressed;
  final String label;
  final bool initialState;
  const ToggleableButton({
    Key? key,
    this.onPressed,
    required this.label,
    this.initialState = false,
  }) : super(key: key);

  @override
  State<ToggleableButton> createState() => _ToggleableButtonState();
}

class _ToggleableButtonState extends State<ToggleableButton> {
  late bool _isActive;
  final Color activeColor = ColorUtil.colorBlue;
  final Color inactiveColor= ColorUtil.colorGray;
  @override
  void initState() {
    super.initState();
    _isActive = widget.initialState;
  }

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: () {
        setState(() {
          _isActive = !_isActive;
        });
        widget.onPressed?.call();
      },
      style: ElevatedButton.styleFrom(
        backgroundColor: _isActive ? activeColor : inactiveColor,
        foregroundColor: Colors.white,
        padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(8),
        ),
      ),
      child: Text(widget.label,style: TextStyle(color: _isActive?Colors.white:Colors.black),),
    );
  }
}